---
title: "Description"
author: "Kohei Watanabe"
date: "`r format(Sys.time(), '%Y-%m-%d')`"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, collapse = FALSE)
require(stringi)
require(quanteda)
```

```{r}
toks_sent <- readRDS("data/data_tokens_sent.RDS")
dat <- docvars(toks_sent)
```

```{r, asis=TRUE}
dat <- subset(dat, !is.na(topic_human))
dat_topic <- as.data.frame.matrix(table(paste(dat$country, dat$year), dat$topic_human))
dat_topic$country <- stri_extract_first_regex(rownames(dat_topic), "\\w+")
dat_topic$year <- stri_extract_first_regex(rownames(dat_topic), "\\d+")
col <- c("year", "country", "greeting", "un", "security", "human", "democracy", "development")
dat_topic <- dat_topic[order(dat_topic$year, dat_topic$country), col]
dat_topic$n <- rowSums(dat_topic[,tail(col, 5)])
knitr::kable(dat_topic)
```
